/* ==================================================================   
 * Created [2009-4-27 下午11:32:55] by Jon.King 
 * ==================================================================  
 * TSS 
 * ================================================================== 
 * mailTo:jinpujun@hotmail.com
 * Copyright (c) Jon.King, 2009-2012 
 * ================================================================== 
 */

package com.jinhe.tss.cms.entity;

import java.util.HashMap;
import java.util.Map;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import javax.persistence.UniqueConstraint;

import com.jinhe.tss.cms.CMSConstants;
import com.jinhe.tss.core.persistence.IEntity;
import com.jinhe.tss.core.util.BeanUtil;
import com.jinhe.tss.core.web.dispaly.tree.ILevelTreeNode;
import com.jinhe.tss.core.web.dispaly.tree.TreeAttributesMap;
import com.jinhe.tss.core.web.dispaly.xform.IXForm;

/**
 * 文章类型ArticleType实体对象
 */
@Entity
@Table(name = "cms_articletype", uniqueConstraints = { 
        @UniqueConstraint(name="MULTI_NAME_TYPENAME", columnNames = { "PARENTID", "name" })
})
@SequenceGenerator(name = "articleType_sequence", sequenceName = "articleType_sequence", initialValue = 1, allocationSize = 1)
public class ArticleType implements IEntity, ILevelTreeNode, IXForm {

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO, generator = "articleType_sequence")
    private Long   id;        // 文章种类编号 PK
    
    @Column(nullable = false)
    private String name;      // 名称
    
    private Long   parentId;  // 父文章种类编号
    
    @Column(nullable = false)
    private Integer isGroup;    // 是否文章类型组 1:是 0：不是
    
    private String publishArticleClassName; // 发布文章实现类
    
    @Column(length = 4000)
    private String articleTemplate;         // 文章展示修饰代码

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }
 
    public String getName() {
        return name;
    }
 
    public void setName(String name) {
        this.name = name;
    }
 
    public Long getParentId() {
        return parentId;
    }
 
    public void setParentId(Long parentId) {
        this.parentId = parentId;
    }
 
    public Integer getIsGroup() {
        return isGroup;
    }
 
    public void setIsGroup(Integer isGroup) {
        this.isGroup = isGroup;
    }
 
    public String getPublishArticleClassName() {
        return publishArticleClassName;
    }
 
    public void setPublishArticleClassName(String publishArticleClassName) {
        this.publishArticleClassName = publishArticleClassName;
    }
 
    public String getArticleTemplate() {
        return articleTemplate;
    }
 
    public void setArticleTemplate(String articleTemplate) {
        this.articleTemplate = articleTemplate;
    }

    public TreeAttributesMap getAttributes() {
        TreeAttributesMap map = new TreeAttributesMap(id, name);
        map.put("state", isGroup);
        
        String iconPath;
        if (CMSConstants.TRUE.equals(isGroup)) {
            iconPath = "../platform/images/icon/article_type_group.gif";
        } else{
            iconPath = "../platform/images/icon/article_type.gif";
        }
        map.put("icon", iconPath);
        return map;
    }

    public Map<String, Object> getAttributesForXForm() {
        Map<String, Object> map = new HashMap<String, Object>();
        BeanUtil.addBeanProperties2Map(this, map);
        return map;
    }
    
    public boolean isTypeGroup(){
        return CMSConstants.TRUE.equals(this.isGroup);
    }
    
    public String getEntityCode(){
        return "article" + this.id;
    }
}
